<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib uri="/struts-tags" prefix="s"%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<title></title>
<jsp:include page="../links.jsp"></jsp:include>
</head>
<body>
	<script type="text/javascript">
		var lost_datagrid;
		var lost_searchForm;
		var lost_addDlg;
		var lost_addForm;
		var lost_updateDlg;
		var lost_updateForm;
		$(function() {
			lost_datagrid = $('#lost_datagrid').datagrid({
				url : getRootPath() + '/admin/lostAction/datagrid.do',
				title : '丢物列表',
				iconCls : 'icon-save',
				pagination : true,
				rownumbers : true,
				selectOnCheck : true,
				checkOnSelect : false,
				pageSize : 10,
				pageList : [ 10, 20, 30, 40, 50 ],
				fit : true,
				fitColumns : true,
				nowarp : false,
				border : false,
				idField : 'lid',
				sortOrder : 'asc',
				columns : [ [ {
					title : '',
					field : '0',
					width : 100,
					checkbox : true
				}, {
					title : '编号',
					field : 'lid',
					width : 100,
					sortable : false
				}, {
					title : '用户编号',
					field : 'uid',
					width : 100,
					sortable : false
				}, {
					title : '失物名称',
					field : 'name',
					width : 200,
				}, {
					title : '图片路径',
					field : 'imgurl',
					width : 150
				//	formatter : function(imgurl, row, index) {//使用formatter格式化刷子
				//		return "<img src='" + getRootPath() + "/" + imgurl + "' width='20px' height='20px'/>";
				//	}
				}, {
					title : '丢失地点',
					field : 'location',
					width : 200,
				}, {
					title : '丢失时间',
					field : 'losttime',
					width : 150,
				}, {
					title : '联系人电话',
					field : 'phone',
					width : 100,
				} ] ],
				toolbar : [ {
					text : '添加',
					iconCls : 'icon-add',
					handler : function() {
						lost_showAddDlg();
					}
				}, '-', {
					text : '修改',
					iconCls : 'icon-edit',
					handler : function() {
						lost_showUpdateDlg();
					}
				}, '-', {
					text : '删除',
					iconCls : 'icon-remove',
					handler : function() {
						lost_remove();
					}
				} ]
			});//datagrid end
			//过滤查询
			lost_searchForm = $('#lost_searchForm').form();
			lost_doSearch = function() {
				//console.info(serializeObject(lost_searchForm));
				lost_datagrid.datagrid('load', serializeObject(lost_searchForm));
			};
			//重置
			lost_cleanSearch = function() {
				lost_datagrid.datagrid('load', {});
				lost_searchForm.find('input').val('');
			};
			//新增
			lost_addDlg = $('#lost_addDlg').dialog();
			lost_addForm = $('#lost_addForm').form();
			lost_showAddDlg = function() {
				$('#lost_addForm input').val('');
				lost_addDlg.dialog('open')
			};
			lost_doAdd = function() {
				lost_addForm.form('submit', {
					url : '${pageContext.request.contextPath}/admin/lostAction/add.do',
					success : function(data) {
						var r = $.parseJSON(data);
						if (r && r.success) {
							lost_addDlg.dialog('close');
							lost_cleanSearch();
							$.messager.show({
								title : '提示',
								msg : r.msg,
								showType : 'show'
							});
						} else {
							$.messager.alert('提示', r.msg);
						}
					}
				});
			};
			//修改
			lost_updateDlg = $('#lost_updateDlg').dialog();
			lost_updateForm = $('#lost_updateForm').form();
			lost_showUpdateDlg = function() {
				var selectids = lost_datagrid.datagrid('getChecked');
				if (selectids.length == 1) {
					lost_updateDlg.dialog('open');
					$('#lost_up_lid').val(selectids[0].lid);
					$('#lost_up_uid').val(selectids[0].uid);
					$('#lost_up_name').val(selectids[0].name);
					$('#lost_up_location').val(selectids[0].location);
					$('#lost_up_losttime').val(selectids[0].losttime);
					$('#lost_up_phone').val(selectids[0].phone);
				} else {
					$.messager.alert('提示', "请勾选一项");
				}
			};
			lost_doUpdate = function() {
				lost_updateForm.form('submit', {
					url : '${pageContext.request.contextPath}/admin/lostAction/update.do?',
					success : function(data) {
						var r = $.parseJSON(data);
						if (r && r.success) {
							lost_updateDlg.dialog('close');
							lost_cleanSearch();
							$.messager.show({
								title : '提示',
								msg : r.msg,
								showType : 'show'
							});
						} else {
							$.messager.alert('提示', r.msg);
						}
					}
				});
			};
			//删除
			lost_remove = function() {
				var selectids = lost_datagrid.datagrid('getChecked');
				var ids = [];
				if (selectids.length > 0) {
					$.messager.confirm('确认', '您是否要删除当前选中的项目？', function(r) {
						if (r) {
							for (var i = 0; i < selectids.length; i++) {
								ids.push(selectids[i].lid);
							}
							$.ajax({
								url : '${pageContext.request.contextPath}/admin/lostAction/delete.do',
								data : {
									ids : ids.join(',')
								},
								dataType : 'json',
								success : function(r) {
									lost_datagrid.datagrid('load');
									lost_datagrid.datagrid('unselectAll');
									$.messager.show({
										title : '提示',
										msg : r.msg
									});
								}
							});
						}
					});
				} else {
					$.messager.alert('提示', "请最少勾选一项");
				}
			};
		});
	</script>
	<div class="easyui-layout" data-options="fit:true,border:false">
		<div data-options="region:'north',title:'模糊查询条件：(右边可折叠)'" style="height: 100%;">
			<form id="lost_searchForm" method="post">
				<table style="width: 100%; height: 60%;">
					<tr>
						<th>失物名称:</th>
						<td><input name="lost.name" /></td>
						<th>丢失地点:</th>
						<td><input name="lost.location" />&nbsp;<a class="easyui-linkbutton" style="width: 25%"
							data-options="iconCls:'icon-search'" href="javascript:void(0)" onclick="lost_doSearch();">查询</a></td>
					</tr>
					<tr>
						<th>丢失时间</th>
						<td><input name="lost.losttimeStart" class="easyui-datetimebox" editable="false" /></td>
						<th>至</th>
						<td><input name="lost.losttimeEnd" class="easyui-datetimebox" editable="false" />&nbsp;<a
							class="easyui-linkbutton" style="width: 25%" data-options="iconCls:'icon-redo'"
							href="javascript:void(0)" onclick="lost_cleanSearch();">清空</a></td>
					</tr>
				</table>
			</form>
		</div>
		<div data-options="region:'center',title:''," style="overflow: hidden;">
			<table id="lost_datagrid">
			</table>
		</div>
		<div id="lost_addDlg"
			data-options="closed:true,modal:true,title:'添加失物',buttons:[
				{text : '添加',iconCls : 'icon-add',handler : function() {lost_doAdd();}},
				{text : '取消',iconCls : 'icon-cancel',handler : function() {lost_addDlg.dialog('close');}}]"
			class="easyui-dialog" style="width: 350px; height: 230px;" align="center">
			<form id="lost_addForm" method="post" enctype="multipart/form-data">
				<table>
					<tr>
						<th class="th-label-width">失物名称:</th>
						<td><input name="lost.name" class="easyui-validatebox" data-options="required:true" /></td>
					</tr>
					<tr>
						<th class="th-label-width">用户编号:</th>
						<td><input name="lost.uid" maxLength=10 class="easyui-validatebox" type="number"
							data-options="required:true,validType:['length[0,10]','number'],missingMessage:'请输入10位数字'" value="" /></td>
					</tr>
					<tr>
						<th class="th-label-width">图片:</th>
						<td><input name="image" type="file" /></td>
					</tr>
					<tr>
						<th class="th-label-width">丢失地点:</th>
						<td><input name="lost.location" class="easyui-validatebox" data-options="required:true" /></td>
					</tr>
					<tr>
						<th class="th-label-width">丢失时间:</th>
						<td><input name="lost.losttime" class="easyui-validatebox easyui-datetimebox" editable="false"
							type="text" data-options="required:true" /></td>
					</tr>
					<tr>
						<th class="th-label-width">联系电话:</th>
						<td><input name="lost.phone" class="easyui-validatebox" data-options="required:true" /></td>
					</tr>
				</table>
			</form>
		</div>
		<div id="lost_updateDlg"
			data-options="closed:true,modal:true,title:'修改失物信息',buttons:[
				{text : '修改',iconCls : 'icon-save',handler : function() {lost_doUpdate();}},
				{text : '取消',iconCls : 'icon-cancel',handler : function() {lost_updateDlg.dialog('close');}}]"
			class="easyui-dialog" style="width: 350px; height: 250px;" align="center">
			<form id="lost_updateForm" method="post" enctype="multipart/form-data">
				<table>
					<tr>
						<th class="th-label-width">编号:</th>
						<td><input id="lost_up_lid" name="lost.lid" class="easyui-validatebox" data-options="required:true"
							readonly="readonly" /></td>
					</tr>
					<tr>
						<th class="th-label-width">失物名称:</th>
						<td><input id="lost_up_name" name="lost.name" class="easyui-validatebox"
							data-options="required:true" /></td>
					</tr>
					<tr>
						<th class="th-label-width">用户编号:</th>
						<td><input id="lost_up_uid" name="lost.uid" maxLength=10 class="easyui-validatebox" type="number"
							data-options="required:true,validType:['length[0,10]','number'],missingMessage:'请输入10位数字'" value="" /></td>
					</tr>
					<tr>
						<th class="th-label-width">图片:</th>
						<td><input name="image" type="file" /></td>
					</tr>
					<tr>
						<th class="th-label-width">丢失地点:</th>
						<td><input id="lost_up_location" name="lost.location" class="easyui-validatebox"
							data-options="required:true" /></td>
					</tr>
					<tr>
						<th class="th-label-width">丢失时间:</th>
						<td><input id="lost_up_losttime" name="lost.losttime" class="easyui-validatebox easyui-datetimebox"
							editable="false" type="text" data-options="required:true" /></td>
					</tr>
					<tr>
						<th class="th-label-width">联系电话:</th>
						<td><input id="lost_up_phone" name="lost.phone" class="easyui-validatebox"
							data-options="required:true" /></td>
					</tr>
				</table>
			</form>
		</div>
	</div>
</body>
</html>